﻿using Domain.Entity;
using Domain.Repository;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCore.Repositorys
{
    public class CPCRepository : ICPCRepository
    {
        private readonly MyDbContext myDbContext;

        public CPCRepository(MyDbContext dbContext)
        {
            myDbContext = dbContext;
        }
        public async Task<List<CPC>> GetCPCAttributeKindAsync(string AttributeKind)
        {
            return await myDbContext.CPC.Where(c => c.AttributeKind == AttributeKind).ToListAsync();
        }
        //删除
        public async Task<bool> DeleteCPCAsync(int id)
        {
            CPC cpc = await myDbContext.CPC.FindAsync(id);
            if (cpc == null)
            {
                return false;
            }

            myDbContext.CPC.Remove(cpc);
            int changes = await myDbContext.SaveChangesAsync();
            return changes > 0;
        }
        //查询全部
        public async Task<List<CPC>> GetCPCAstnc()
        {
            return await myDbContext.CPC.ToListAsync();
        }
        //新增
        public async Task<bool> AddCPCAsync(CPC cpc)
        {
            myDbContext.CPC.Add(cpc);
            return await myDbContext.SaveChangesAsync() > 0;
        }
    }
}
